/**
 * 
 */


import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * @author Tai Nguyen - T133110
 * 
 */
public class cPro02_CountNumbers_T133110 extends JFrame {
	JLabel lbl = new JLabel("Input So Nguyen n");
	JLabel lbl2 = new JLabel("Input n So Nguyen");
	JLabel lbl1 = new JLabel("Output");
	
	JTextField txt1 = new JTextField();
	JTextField txt = new JTextField();
	JTextArea txt2 = new JTextArea();
	JButton btn = new JButton("Clear");
	JButton btn1 = new JButton("ClearALL");
	JButton btn2 = new JButton("Calculate");
	int iso=0,iso1=0;
	public cPro02_CountNumbers_T133110() {
		setSize(500, 500);
		setTitle("CountNumbers - T133110");
		setLayout(null);
		add(lbl);
		add(lbl1);
		add(txt);
		add(txt1);
		add(btn1);
		add(txt2);
		add(btn2);
		add(btn);
		add(lbl2);
		lbl.setBounds(10, 20, 150, 20);
		lbl2.setBounds(10, 50, 150, 20);
		
		lbl1.setBounds(10, 120, 150, 20);
		
		txt.setBounds(160, 20, 170, 20);
		txt1.setBounds(160, 50, 170, 20);
		
		txt2.setBounds(160, 120, 300, 100);
		btn.setBounds(160, 80, 80, 20);
		btn1.setBounds(250, 80, 80, 20);
		btn2.setBounds(340, 50, 100, 20);
		Insets thin = new Insets(1, 1, 1, 1);
		btn1.setMargin(thin);
	
		ActionListener btnlink = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				try {
				
				if (e.getSource() == btn) {
					txt.setText("");
					txt1.setText("");
				}
				if (e.getSource() == btn1) {
					txt1.setText("");
					txt.setText("");
					txt2.setText("");
				}
				
				
				if (e.getSource() == btn2) {
					

					
					String [] sa;
					
					int ia = Integer.parseInt(txt.getText());
					String s=txt1.getText().trim();
					int iarray [] = new int [ia];
					
					
						sa= s.split(" ");
					
				
					for(int i = 0;i<sa.length;i++) {
						iarray[i]=Integer.parseInt(sa[i]);
						txt2.setText(sa[i]);
					}
				
					for(int i=0;i<sa.length;i++) {
						
					if(iarray[i]%2==0 &iarray[i]%3!=0) {
						iso++;
					}
					
					if(iarray[i]%3==0 &iarray[i]%5!=0) {
						iso1++;
					}}
					
					txt2.setText("so cac so chia het cho 2 va khong chia het cho 3 : \n "+iso+"\nso cac so chia het cho 3 va khong chia het cho 5 :\n"+iso1);
					
					
					}
						
					
					}
				catch (ArrayIndexOutOfBoundsException h) {
					txt2.setText("Invalid Input");}
			}
		};
		btn.addActionListener(btnlink);
		btn1.addActionListener(btnlink);
		btn2.addActionListener(btnlink);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		cPro02_CountNumbers_T133110 main = new cPro02_CountNumbers_T133110();
		main.setDefaultCloseOperation(EXIT_ON_CLOSE);
		main.setVisible(true);
	}

}
